//
//  ViewController.m
//  intrinsicView
//
//  Created by 李煜 on 2021/8/9.
//https://www.cnblogs.com/siasyl/p/6055273.html

#import "ViewController.h"
#import "IntrinsicView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self testIntrinsicView];
}

- (void)testIntrinsicView {
    IntrinsicView *greenView = [IntrinsicView new];
    greenView.extendSize = CGSizeMake(100, 100);
    greenView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:greenView];
    [self.view  addConstraints:@[
        [NSLayoutConstraint constraintWithItem:greenView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:100],
        [NSLayoutConstraint constraintWithItem:greenView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:10]]];
    
    
    //约束redView
    IntrinsicView *redView = [IntrinsicView new];
    redView.backgroundColor = [UIColor redColor];
    redView.extendSize = CGSizeMake(100, 30);
    [self.view addSubview:redView];
    [self.view addConstraints:@[
        [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:greenView attribute:NSLayoutAttributeBottom multiplier:1 constant:20],
        [NSLayoutConstraint constraintWithItem:redView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:greenView attribute:NSLayoutAttributeLeft multiplier:1 constant:0]
    ]];
    
    [self performSelector:@selector(testInvalidateIntrinsic:) withObject:redView afterDelay:2.0];
}

- (void)testInvalidateIntrinsic:(IntrinsicView *)view {
    view.extendSize = CGSizeMake(100, 80);
}


@end
